package ts.test.test;

import java.lang.reflect.Field;

public class AccesPersonFields {
    public static void main(String[] args) {
        try  {
            //通过反射加载一个Person类
            Class cls = Class.forName("ts.test.test.Parson");
            Object  person = cls.newInstance();
            //获取Person类中的name属性
            Field name = cls.getDeclaredField("name");
            name.setAccessible(true);
            System.out.println("赋值前的name：" +name.get(person));
            name.set(person,"New Person");
            System.out.println("赋值后的name：" +name.get(person));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
